<div class="tab-pane" id="permission">
	<?php $form = $this->beginWidget('CActiveForm', array(
		'id' => 'permission-modify-form',
		'action' => url('user/midifypermission'),
		'enableClientValidation' => true,
		'clientOptions' => array(
			'validateOnSubmit' => true,
		),
	)); ?>
		<input type="hidden" name="id_user_role" class="id_user_role_hidden" />
	
		<!-- the hidden fields below are used to post the unchecked checkbox -->
		<label class="checkbox">
			<input type="hidden" name="Perm[account_manage]" />
			<input type="checkbox" value="1" id="Perm_account_manage" name="Perm[account_manage]" class="fields" /> <?php echo t('info', 'Manage WHM Accounts'); ?> 
		</label> 
		<label class="checkbox">
			<input type="hidden" name="Perm[account_search]" />
			<input type="checkbox" value="1" id="Perm_account_search" name="Perm[account_search]" class="fields" /> <?php echo t('info', 'Search WHM Accounts'); ?> 
		</label>
		<label class="checkbox">
			<input type="hidden" name="Perm[group_manage]" />
			<input type="checkbox" value="1" id="Perm_group_manage" name="Perm[group_manage]" class="fields" /> <?php echo t('info', 'Manage Groups'); ?>
		</label>
		<label class="checkbox">
			<input type="hidden" name="Perm[host_manage]" />
			<input type="checkbox" value="1" id="Perm_host_manage" name="Perm[host_manage]" class="fields" /> <?php echo t('info', 'Manage Web Hosts'); ?> 
		</label>
		<label class="checkbox">
			<input type="hidden" name="Perm[user_manage]" />
			<input type="checkbox" value="1" id="Perm_user_manage" name="Perm[user_manage]" class="fields" /> <?php echo t('info', 'Manage Users'); ?>
		</label>
		<label class="checkbox">
			<input type="hidden" name="Perm[backup_manage]" />
			<input type="checkbox" value="1" id="Perm_backup_manage" name="Perm[backup_manage]" class="fields" /> <?php echo t('info', 'Manage Backups'); ?> 
		</label>
		<label class="checkbox">
			<input type="hidden" name="Perm[config_manage]" />
			<input type="checkbox" value="1" id="Perm_config_manage" name="Perm[config_manage]" class="fields" /> <?php echo t('info', 'Manage Configuration'); ?> 
		</label> <br />
		
		<button class="btn btn-small btn-primary" type="submit" id="save-role-permisson">
			<i class="radmin-icon radmin-fire"></i> <?php echo t('buttons', 'Save'); ?>
		</button>
		<script>
//			$(document).ready(function(){
//				$('#save-role-permisson').click(function(){
//					$.ajax({
//						type: 'post',
//						url: <?php echo json_encode(url('user/midifypermission')); ?>,
//						data: $('#permission-modify-form').serialize(),
//						success: function(ret){
//							
//						},
//						dataType: 'json'
//					});
//				});

				$('#id_user_role').change(function(){
					var obj = $(this);
					$.ajax({
						type: 'get',
						url: <?php echo json_encode(url('user/getpermissiondetail')); ?>,
						data: {'id_user_role': obj.val()},
						success: function(detail){
							$('#permission-modify-form .fields').removeAttr('checked');
							if(detail){
								$('#permission-modify-form .fields').removeAttr('disabled');
								if(detail.role.supreme == 1){
									$('#permission-modify-form .fields').attr('disabled', 'disabled');
								}
								$.each(detail.perm, function(key, value){
									if(value){
										$('#permission-modify-form #Perm_'+key).attr('checked', 'checked');
									}
								});
							}
						},
						dataType: 'json'
					});
				});
//			});
		</script>
	<?php $this->endWidget(); ?>
</div>